#encoding:utf8

"""
base api for debug
"""
import json
import copy

return_data = dict(code=0, msg="", data="")


class SpiderUrlApi(object):
    def __init__(self, *args, **kwargs):
        self.data = []

    def insert(self, data):
        result = copy.deepcopy(return_data)
        result['data'] = data
        self.data.append(data)
        return json.dumps(result)

    def _ignore(self, data=None):
        result = copy.deepcopy(return_data)
        result['data'] = "ignored"
        d = json.dumps(result)
        return d

    update = _ignore
    update_query = _ignore
    update_status = _ignore

    def clear(self):
        self.data = []
        d = json.dumps(return_data)
        return d

    def get(self):
        result = copy.deepcopy(return_data)
        try:
            d = self.data.pop()
            result['data'] = d
        except IndexError, ex:
            result['code'] = -1
            result['msg'] = "list is empty"
        return json.dumps(result)

    start_queue = _ignore
    stop_queue = _ignore


class SpiderDBApi(object):
    def __init__(self, *args, **kwargs):
        self.data = []

    def _ignore(self, data=None):
        result = copy.deepcopy(return_data)
        result['data'] = "ignored"
        d = json.dumps(result)
        return d
    update = _ignore
    insert = _ignore
    clear = _ignore
    get = _ignore




